package cn.zf233.xcloud.config;

import cn.zf233.xcloud.commom.Const;
import cn.zf233.xcloud.util.RedisUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by zf233 on 2021/3/25
 * XCloud启动任务配置
 */
// @Configuration
public class XcloudStartFinishConfig {

    @Value("${xcloud.app.version}")
    private String appVersion;

    @Component
    @Order(value = 1) // 指定其执行顺序，值越小优先级越高
    public class XcloudStartFinishTask implements ApplicationRunner {

        @Resource
        private RedisUtil redisUtil;
        private String appVersionCode;

        @Override
        public void run(ApplicationArguments args) {
            this.appVersionCode = appVersion;
            redisUtil.set(Const.APP_VERSION, this.appVersionCode);
        }

        public String getAppVersionCode() {
            return this.appVersionCode;
        }
    }

    @Component("appVersionObject")
    @ConfigurationProperties(prefix = "xcloud.app")
    @PropertySource("classpath:version.properties")
    public static class AppVersion {

        private String version;

        public AppVersion() {
        }

        public AppVersion(String appVersion) {
            this.version = appVersion;
        }

        public String getVersion() {
            return version;
        }

        public void setVersion(String version) {
            this.version = version;
        }
    }
}